﻿Option Explicit On

Imports MySql.Data.MySqlClient
Imports Microsoft.Office.Interop
Imports System.Threading
Public Class frmrpt_depotdetail
    Dim mySqlCommand As New MySqlCommand
    Dim mySqlAdaptor As New MySqlDataAdapter
    Dim mySqlReader As MySqlDataReader
    Dim respone As Object
    Dim mysql As MySqlConnection = main_form.mysqlconection
    Public Shared voystart As Integer = 0
    Public Shared voyEnd As Integer = 0
    Private Sub ButtonX2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonX2.Click
        Dim CheckIndex As Integer

        Dim CheckData As Boolean
        CheckData = False
        CheckIndex = ListView1.Items.Count

            mysql.Close()

            If mysql.State = ConnectionState.Closed Then
                mysql.Open()
            End If
        ListView1.Items.Clear()

        For i = CInt(TextBoxX1.Text) To CInt(TextBoxX2.Text)
            mysql.Close()

            If mysql.State = ConnectionState.Closed Then
                mysql.Open()
            End If
            mySqlCommand.CommandText = "Select VOYAGEID,VOYVESNAMEN,VOYDATEEN,VOYTIMEHHMMNN,COUNT(case when ctnstatdepot =1 then ctnmain.CTNMAINID else NULL end) as ctn_all ,COUNT(case when ctnstatdepot =2 then ctnmain.CTNMAINID else NULL end) as ctn_wt,COUNT(case when ctnstatdepot =3 then ctnmain.CTNMAINID else NULL end) as ctn_dm, COUNT(case when ctnstatdepot =0 then ctnmain.CTNMAINID else NULL end) as ctn_use from voyage join ctnmain on voyage.VOYAGEID = ctnmain.CTNVOYN join ctndepot on ctnmain.CTNMAINID = ctndepot.CTNID where  VOYAGEID = '" & i.ToString & "'   GROUP BY VOYAGEID ;"        ' mySqlCommand.CommandText = 
            mySqlCommand.Connection = mysql
            mySqlAdaptor.SelectCommand = mySqlCommand

            Try
                mySqlReader = mySqlCommand.ExecuteReader

                While (mySqlReader.Read())


                    With ListView1.Items.Add(Format(mySqlReader("VOYAGEID"), "000"))

                        .SubItems.Add("N")
                        .SubItems.Add(mySqlReader("VOYVESNAMEN"))

                        .SubItems.Add(mySqlReader("VOYDATEEN"))
                        .SubItems.Add(mySqlReader("VOYTIMEHHMMNN"))
                        .SubItems.Add(mySqlReader("ctn_all"))
                        .SubItems.Add(mySqlReader("ctn_use"))
                        .SubItems.Add(mySqlReader("ctn_dm"))
                        .SubItems.Add(mySqlReader("ctn_wt"))
                    End With


                End While
            Catch ex As Exception

            End Try
        Next


    End Sub

    Private Sub frmrpt_depotdetail_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.CreateSpecificCulture("en-US")
        System.Threading.Thread.CurrentThread.CurrentUICulture = System.Threading.Thread.CurrentThread.CurrentCulture
        mysql.Close()

    End Sub
   
    Private Sub SuperTabControlPanel2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SuperTabControlPanel2.Click

    End Sub

    Private Sub ButtonX1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonX1.Click
        voystart = CInt(TextBoxX1.Text)
        voyEnd = CInt(TextBoxX2.Text)
        Dim nextform As frmrpt_depotgrapth = New frmrpt_depotgrapth
        nextform.Show()
    End Sub

    Private Sub SuperTabControl1_SelectedTabChanged(ByVal sender As System.Object, ByVal e As DevComponents.DotNetBar.SuperTabStripSelectedTabChangedEventArgs) Handles SuperTabControl1.SelectedTabChanged

    End Sub
End Class